#include <accent/algorithms/reverse.hpp>
#include <accent/algorithms/concat.hpp>
#include "test_base.hpp"

TEST(ConcatReverse, twoAndTwo)
{
  ivec v1 = { 1, 2 }, v2 = { 3, 4 },
       e1 = { 4, 3 }, e2 = { 2, 1 };
  auto r = concat(all(v1), all(v2));
  reverse(r);
  ASSERT_EQ(e1, v1);
  ASSERT_EQ(e2, v2);
}

TEST(ConcatReverse, twoAndTwoWithPos0)
{
  ivec v1 = { 1, 2 }, v2 = { 3, 4 },
       e1 = { 4, 3 }, e2 = { 2, 1 };
  auto r = concat(all(v1), all(v2));
  auto p = reverse_with_position(r, r.front_position());
  ASSERT_EQ(e1, v1);
  ASSERT_EQ(e2, v2);
  ASSERT_FALSE(!p);
  ASSERT_EQ(1, *p);
}

TEST(ConcatReverse, twoAndTwo_reverseFirstTwoWithPos0)
{
  ivec v1 = { 1, 2 }, v2 = { 3, 4 },
       e1 = { 2, 1 }, e2 = { 3, 4 };
  auto r = concat(all(v1), all(v2)), s = r;
  s.pop_front();
  s.pop_front();
  auto p = reverse_with_position(r.until(s.front_position()),
                                 r.front_position());
  ASSERT_EQ(e1, v1);
  ASSERT_EQ(e2, v2);
  ASSERT_FALSE(!p);
  ASSERT_EQ(1, *p);
}

TEST(ConcatReverse, twoAndTwo_reverseLastTwoWithPos2)
{
  ivec v1 = { 1, 2 }, v2 = { 3, 4 },
       e1 = { 1, 2 }, e2 = { 4, 3 };
  auto r = concat(all(v1), all(v2)), s = r;
  s.pop_front();
  s.pop_front();
  auto p = reverse_with_position(r.from(s.front_position()),
                                 s.front_position());
  ASSERT_EQ(e1, v1);
  ASSERT_EQ(e2, v2);
  ASSERT_FALSE(!p);
  ASSERT_EQ(3, *p);
}
